#include "main.h"
#include "trayicon.h"

TrayIcon::TrayIcon( MainFrame* pFrame )
: m_cIcon( tt_16x16_xpm )
{
	m_pcFrame = pFrame;
	this->Connect( wxEVT_TASKBAR_LEFT_DOWN, wxTaskBarIconEventHandler( TrayIcon::OnLeftClick ) );		
	
	m_pcContextMenu = new wxMenu();
	wxMenuItem *menuItemExit = new wxMenuItem( m_pcContextMenu, wxID_ANY, wxString( _("Exit") ) );
	menuItemExit->SetBitmap( wxArtProvider::GetBitmap( wxART_QUIT ) );
	m_pcContextMenu->Append( menuItemExit );
	this->Connect( wxID_ANY, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( TrayIcon::OnExitClick ) );
}

TrayIcon::~TrayIcon()
{
	this->Disconnect( wxEVT_TASKBAR_LEFT_DOWN, wxTaskBarIconEventHandler( TrayIcon::OnLeftClick ) );
	this->Disconnect( wxID_ANY, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( TrayIcon::OnExitClick ) );	
}

void TrayIcon::SetIcon()
{
	if( !wxTaskBarIcon::SetIcon( m_cIcon , wxT( "TanoTutor" ) ) )
		wxMessageBox( wxT( "Could not set icon." ) );		
}

void TrayIcon::OnLeftClick( wxTaskBarIconEvent& event )
{
	m_pcFrame->OnShowEvent( (wxCommandEvent&) event );
}

wxMenu* TrayIcon::CreatePopupMenu()
{
	return m_pcContextMenu;
}

void TrayIcon::OnExitClick( wxCommandEvent& event )
{
	m_pcFrame->OnExitClick( event );
}